/*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
package service;

import dao.NovelDao;
import dao.NovelchapterDao;
import entity.Novalchapter;
import entity.Novel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class NovalService {

	@Resource
	private NovelDao novelDao;

	@Resource
	private NovelchapterDao novelchapterDao;

	public void saveNova(List<Novalchapter> novalchapters, Novel novel) {
		this.novelDao.save(novel);
		Long novalid = novel.getId();
		for (Novalchapter n : novalchapters) {
			n.setNovelid(novalid.longValue());
		}
		this.novelchapterDao.save(novalchapters);
	}

	public List<Novel> getNovels() {
		return this.novelDao.find("from Novel");
	}

	public Novalchapter getNovelchapter(int chapterid, long novelid) {
		Map map = new HashMap();
		map.put("chapterid", Integer.valueOf(chapterid));
		map.put("novelid", Long.valueOf(novelid));
		List chapter = null;

		chapter = this.novelchapterDao
				.find("from Novalchapter where chapterid=:chapterid and novelid=:novelid",
						map);
		return ((Novalchapter) chapter.get(0));
	}

	public Novel getNovel(long novelid) {
		Map map = new HashMap();
		map.put("id", Long.valueOf(novelid));
		Novel novel = (Novel) this.novelDao.get("from Novel where id=:id", map);
		return novel;
	}
}